package com.dalin.demo.controller;

import com.dalin.demo.pojo.entity.OaMessage;
import com.dalin.demo.service.OaMessageService;
import com.dalin.framework.util.LogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/oaMessage")
@CrossOrigin(origins = "*")
public class OaMessageController {
    private LogUtil log = LogUtil.getLogger(OaMessageController.class);

    @Autowired
    private OaMessageService oaMessageService;

    @GetMapping("/all")
    public List<OaMessage> getAllOaMessages() {
        log.info("getAllOaMessages===");
        return oaMessageService.getAllOaMessages();
    }
    @GetMapping("/list")
    public List<OaMessage> listOaMessages(@RequestParam Map<String, Object> params) {
        log.debug("listOaMessages by params==="+ params);
        return oaMessageService.listOaMessagesByParams(params);
    }

    @PostMapping("/add")
    public OaMessage addOaMessage(@RequestBody OaMessage oaMessage) throws Exception {
        log.debug("addOaMessage===");
        oaMessageService.addOaMessage(oaMessage);
        return oaMessage;
    }

    @DeleteMapping("/delete/{id}")
    public String deleteOaMessage(@PathVariable Integer id) {
        log.debug("deleteOaMessage by id==="+ id);
        oaMessageService.deleteOaMessage(id);
        return "success";
    }

    @PostMapping("/deleteByIds")
    public String deleteOaMessagesByIds(@RequestBody List<String> ids) {
        log.debug("deleteOaMessages by ids==="+ ids);
        oaMessageService.deleteOaMessages(ids);
        return "success";
    }

    @PostMapping("/update")
    public String updateOaMessage(@RequestBody OaMessage oaMessage) throws Exception {
        oaMessageService.updateOaMessage(oaMessage);
        return "success";
    }
}